package com.ruoyi.hr.service.impl.empinfo;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.hr.domain.Authority;
import com.ruoyi.hr.mapper.ProcedureMapper;
import com.ruoyi.hr.mapper.empinfo.IncumbencyEmpMapper;
import com.ruoyi.hr.service.empinfo.IncumbencyEmpService;
import com.ruoyi.system.domain.SysUser;
import com.ruoyi.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class IncumbencyEmpServiceImpl extends BaseController implements IncumbencyEmpService {

    @Autowired
    IncumbencyEmpMapper incumbencyEmpMapper;

    @Autowired
    ProcedureMapper procedureMapper;

    @Autowired
    SysUserMapper sysUserMapper;

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public List<Map<String, Object>> findDataList(Map map, Authority authority) {
        return incumbencyEmpMapper.findDataList(map, authority);
    }

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public List<Map<String, Object>> findQuitList(Map map, Authority authority) {
        return incumbencyEmpMapper.findQuitList(map, authority);
    }

    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public List<Map<String, Object>> findRetireList(Map map, Authority authority) {
        return incumbencyEmpMapper.findRetireList(map, authority);
    }


    @DataSource(value = DataSourceType.SLAVE)
    @Override
    public List<Map<String, Object>> empInfoHistoryList(Map map, Authority authority) {
        //执行前置存储过程
        SysUser user = ShiroUtils.getSysUser();
        Map<String, Object> maps = sysUserMapper.selectSkySecUser(user.getLoginName());
        String urid = maps.get("id").toString();
        procedureMapper.executeProcedure("eSP_GetHistoryEmp '" + map.get("term") + "',100," + urid);
        startPage();
        map.put("urid",urid);
        return incumbencyEmpMapper.empInfoHistoryList(map,authority);
    }
}
